package longrise.phone.com.bjjt_henan.main;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.longrise.android.FormParameter;
import com.longrise.android.FrameworkManager;
import com.longrise.android.LFView;

import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import longrise.phone.com.bjjt_henan.R;

/**
 * 首页项页面
 */
public class NewHomeView extends LFView implements View.OnClickListener {

    private View mView;

    private Context mContext;

    private LinearLayout trafficLayout;

    private LinearLayout operLayout;

    private LinearLayout recomLayout;

    private RollImageView rollImageView;

    public NewHomeView(Context context) {
        super(context);
        this.mContext = context;
    }

    @Override
    public View getView() {
        return mView;
    }

    @Override
    public FormParameter getFormParameter() {
        return null;
    }

    @Override
    public void init() {
        if (mContext == null) {
            return;
        }
        mView = LayoutInflater.from(mContext).inflate(R.layout.view_newhome, null);
        if (mView == null) {
            return;
        }
        trafficLayout = (LinearLayout) mView.findViewById(R.id.newhome_layout_traffic);
        operLayout = (LinearLayout) mView.findViewById(R.id.newhome_layout_operation);
        recomLayout = (LinearLayout) mView.findViewById(R.id.newhome_layout_recommend);

//        initRollView();
        setListen(true);
    }

    //轮播图片界面
    private void initRollView() {
        LinearLayout imgLayout = (LinearLayout) mView.findViewById(R.id.newhome_layout_imgs);
        if (rollImageView == null) {
            rollImageView = new RollImageView(mContext);
            rollImageView.setNewsType("2");
            rollImageView.init();
            rollImageView.refresh();
        }
        imgLayout.removeAllViews();
        imgLayout.addView(rollImageView.getView(), new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
    }

    private void setListen(boolean flag) {
        if (trafficLayout != null) {
            trafficLayout.setOnClickListener(flag ? this : null);
        }
        if (operLayout != null) {
            operLayout.setOnClickListener(flag ? this : null);
        }
        if (recomLayout != null) {
            recomLayout.setOnClickListener(flag ? this : null);
        }
    }

    @Override
    public void onClick(View v) {
        LFView view = null;
        switch (v.getId()) {
            case R.id.newhome_layout_traffic://出行服务
                view = new TravelServiceView(mContext);
                break;
            case R.id.newhome_layout_operation://操作演示
                view = new ActionDemoView(mContext);
                break;
            case R.id.newhome_layout_recommend://推荐好友
                view = new RecommendView(mContext);
                break;
            default:
                break;
        }
        if (null != view) {
            FrameworkManager.getInstance().showNewForm(mContext, view);
        }
    }

    @Override
    public void refresh() {

    }

    @Override
    public void refreshByTime() {

    }

    @Override
    public void OnDestroy() {
        super.OnDestroy();
        setListen(false);
        if (null != rollImageView) {
            rollImageView.OnDestroy();
            rollImageView = null;
        }
        mView = null;
    }
}
